//
// Created by Crestimes on 24-5-10.
//

#ifndef PARSER_H
#define PARSER_H
#include <vector>
#include <QException>

#include "Token.h"
#include "TreeNode.h"


class Parser {
public:
    explicit Parser(std::vector<Token> tokens);
    TreeNode* getSyntaxTree();

private:
    std::vector<Token> tokens;
    int pos = 0;

    [[nodiscard]] TokenType nextTokenType() const;
    Token match(LeafNodeType);
    static TreeNode* createNode(const Token&);

    TreeNode* program();
    TreeNode* stmt_sequence();
    TreeNode* statement();
    TreeNode* as_rg_stmt();
    TreeNode* regex_stmt();
    TreeNode* if_stmt();
    TreeNode* repeat_stmt();
    TreeNode* assign_stmt();
    TreeNode* read_stmt();
    TreeNode* write_stmt();
    TreeNode* while_stmt();
    TreeNode* for_stmt();

    TreeNode* exp();
    TreeNode* exp_level0();
    TreeNode* exp_level1();
    TreeNode* exp_level2();
    TreeNode* exp_level3();
    TreeNode* exp_level4();

    TreeNode* regex();
    TreeNode* reg_level0();
    TreeNode* reg_level1();
    TreeNode* reg_level2();
    TreeNode* reg_level3();
};


#endif //PARSER_H
